# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sébastien Luttringer

pkgname=dokuwiki
pkgver=20230404
pkgrel=1
_pkgver=${pkgver:0:4}-${pkgver:4:2}-${pkgver:6}
_pkgver=${_pkgver/_/}
_pkgver=${_pkgver/rc/}
[[ $pkgver == *"rc" ]] && _release=candidate || _release=stable
pkgdesc='Simple to use and highly versatile Open Source wiki software'
arch=('any')
url='https://www.dokuwiki.org/'
license=('GPL')
depends=('php')
backup=('etc/webapps/dokuwiki/.htaccess'
        'etc/httpd/conf/extra/dokuwiki.conf')
options=('!strip')
#source=("$pkgname-$pkgver.tar.gz::https://github.com/splitbrain/dokuwiki/archive/release_${_release}_${_pkgver}.tar.gz"
source=("$pkgname-$pkgver.tar.gz::https://github.com/dokuwiki/dokuwiki/releases/download/release-${_pkgver}/dokuwiki-${_pkgver}.tgz"
        'apache.example.conf')
sha256sums=('3e3f97b47a24332ee59ea52286587ab9c342792b91f3eec18c3bf14957117b46'
            '237e11ec2c1cd69d0b7e8cff2169d0072666b31694efd727338c9197199e0f5f')

package() {
  cd "$pkgdir"
  install -dm0755 usr/share/webapps var/lib/dokuwiki etc/webapps
  cp -a "$srcdir"/$pkgname-${_pkgver} usr/share/webapps/dokuwiki

  # move data in var
  mv usr/share/webapps/dokuwiki/data var/lib/dokuwiki
  ln -s {../../../../../var/lib/dokuwiki,usr/share/webapps/dokuwiki}/data

  # move plugins in var
  mv usr/share/webapps/dokuwiki/lib/plugins var/lib/dokuwiki
  ln -s {../../../../../../var/lib/dokuwiki,usr/share/webapps/dokuwiki/lib}/plugins

  # move templates in var
  mv usr/share/webapps/dokuwiki/lib/tpl var/lib/dokuwiki
  ln -s {../../../../../../var/lib/dokuwiki,usr/share/webapps/dokuwiki/lib}/tpl

  # move config in /etc
  mv usr/share/webapps/dokuwiki/conf etc/webapps/dokuwiki
  chmod g=rwx etc/webapps/dokuwiki
  ln -s ../../../../../etc/webapps/dokuwiki usr/share/webapps/dokuwiki/conf

  # inform update on changes.log
  touch var/lib/dokuwiki/data/changes.log
  chmod 0644 var/lib/dokuwiki/data/changes.log

  # use default htaccess
  cp usr/share/webapps/dokuwiki/.htaccess.dist etc/webapps/dokuwiki/.htaccess
  ln -s /etc/webapps/dokuwiki/.htaccess usr/share/webapps/dokuwiki/.htaccess

  # fix rights and ownership
  chown -R 33:33 var/lib/dokuwiki/plugins
  chown -R 33:33 var/lib/dokuwiki/data
  chown -R 33:33 var/lib/dokuwiki/tpl
  chown -R 33:33 etc/webapps/dokuwiki

  # apache config
  install -Dm0644 "$srcdir"/apache.example.conf etc/httpd/conf/extra/dokuwiki.conf

  # php.ini
#  install -dm0755 "$pkgdir"/etc/php/conf.d/
#  echo 'open_basedir = ${open_basedir}:/etc/webapps/dokuwiki/:/var/lib/dokuwiki/' >"$pkgdir"/etc/php/conf.d/dokuwiki.ini
}

# vim:set ts=2 sw=2 et:
